package com.likou.second_challenge;

public class q48 {

    public void rotate(int[][] matrix) {
        int n = matrix.length;
        // 按照主对角线翻转
        for (int i = 1; i < n; i++) {
            for (int j = 0; j <= i - 1; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }

        // 按照中线翻转
        int mid = n / 2;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < mid; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[i][n - j - 1];
                matrix[i][n - j - 1] = temp;
            }
        }

    }

}
